home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ace23.lha / MAIN.lha / include / array_size.h next >
Text File  |  1994-10-22  |  2KB  |  64 lines

  1. {*
  2. ** array_size.h
  3. **
  4. ** Author: David Benn
  5. **   Date: 5th,28th August 1994
  6. **
  7. ** For example:
  8. **
  9. ** -----------------------
  10. ** #include <array_size.h>
  11. **
  12. ** dim a(4,5)
  13. ** print sizeof(a)
  14. ** print array_size_2D(4,5,sizeof(single))
  15. **
  16. ** dim b(4,5,2)
  17. ** print sizeof(b)
  18. ** print array_size_3D(4,5,2,sizeof(single))
  19. ** -----------------------------------------
  20. **
  21. ** When compiled and run, the output of this
  22. ** program is:
  23. **
  24. ** 120
  25. ** 120
  26. ** 360
  27. ** 360
  28. **
  29. ** This shows that array_size_2D/3D calculate the
  30. ** correct number of bytes required to allocate
  31. ** memory for a 2D or 3D array dynamically.
  32. **
  33. ** See also the DIM entry in ref.doc.
  34. *}
  35.  
  36. SUB LONGINT array_size_2D(n,m,element_size)
  37. {* Determine size of memory required
  38. ** for a 2D array of a given element
  39. ** type. The return value from this SUB
  40. ** can be passed to ACE's ALLOC function.
  41. **
  42. ** n = max. index of first dimension
  43. ** m = max. index of second dimension
  44. ** element_size = size in bytes of array element data type
  45. **                (use the SIZEOF function to determine this).
  46. *}
  47.      array_size_2D = (n+1) * (m+1)*element_size
  48. END SUB
  49.  
  50. SUB LONGINT array_size_3D(a,b,c,element_size)
  51. {* Determine size of memory required
  52. ** for a 3D array of a given element
  53. ** type. The return value from this SUB
  54. ** can be passed to ACE's ALLOC function.
  55. **
  56. ** a = max. index of first dimension
  57. ** b = max. index of second dimension
  58. ** c = max. index of third dimension
  59. ** element_size = size in bytes of array element data type
  60. **                (use the SIZEOF function to determine this).
  61. *}
  62.      array_size_3D = (a+1) * (b+1) * (c+1)*element_size
  63. END SUB
  64.